package cn.sc.summer.banner.util;

import cn.hutool.extra.spring.SpringUtil;
import cn.sc.summer.constant.project.ProjectConstant;
import cn.sc.summer.redis.util.NacosInstancesService;
import lombok.extern.slf4j.Slf4j;

import java.time.Duration;

/**
 * 类名：banner打印工具
 *
 * @author a-xin
 * @date 2024/9/23 16:33
 */
@Slf4j
public class PrintUtil {

    /**
     * 微服务打印
     */
    public static void printBanner(Boolean druid, Duration duration) {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(
                "\n\t-------------------------------------------------------------" +
                "\n\tApplication Application-main is running! Access URLs:" +
                "\n\tThe current environment: [ {} ], Time: {}s" +
                "\n\t{} is complete: \thttp://{}");
        if (druid) {
            stringBuilder.append("\n\tDruid Web is complete: \t\thttp://localhost:{}/druid/index.html");
        }
        stringBuilder.append("\n\t-------------------------------------------------------------");

        log.info(stringBuilder.toString(),
                SpringUtil.getActiveProfile(),
                duration.getSeconds(),
                ProjectConstant.SERVER_NAME,
                NacosInstancesService.getServerNacosAddress(),
                ProjectConstant.SERVER_PORT
        );
    }

    /**
     * 网关信息打印
     */
    public static void printBannerGateway(Boolean swagger, Duration duration) {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(
                "\n\t-------------------------------------------------------------" +
                "\n\tApplication Application-main is running! Access URLs:" +
                "\n\tThe current environment: [ {} ], Time: {}s" +
                "\n\t{} is complete: \thttp://{}");
        if (swagger) {
            stringBuilder.append("\n\tSwagger Local document: \t\thttp://localhost:{}/doc.html" +
                    "\n\tSwagger NetWork document: \t\thttp://{}/doc.html");
        }
        stringBuilder.append("\n\t-------------------------------------------------------------");

        log.info(stringBuilder.toString(),
                SpringUtil.getActiveProfile(),
                duration.getSeconds(),
                ProjectConstant.SERVER_NAME,
                NacosInstancesService.getServerNacosAddress(),
                ProjectConstant.SERVER_PORT,
                NacosInstancesService.getServerNacosAddress()
        );
    }

}
